#include "guish.hpp"
#ifndef IOMANAGER_HPP
#define IOMANAGER_HPP
#include <sys/select.h>

class IOUser
{
public:
	IOUser(int order=0);
	virtual ~IOUser();
	
	virtual void prepareSelect(int priority, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, int *maxfd)=0;
	virtual void postSelect(int priority, fd_set *readfds, fd_set *writefds, fd_set *exceptfds)=0;
};

class IOManager
{
public:
	IOManager(EventManager *eventManager);
	~IOManager();
	bool doIO(bool canBlock, int priority);
	
protected:
	friend class IOUser;
	multimap<int, IOUser*> ioUsers;
	int selfpipe[2];
};

extern IOManager *ioManager;

#endif
